import getMAC from 'getmac';

export const HEADERCLIENTID = 'x-client-id';
export const WSHEADERCLIENTID = 'x-ws-client';

export function getClientId() {
    return 'd' + getMAC().split(':').join('') + "d";
}

export function isClientId(id) {
    return /d[0-9a-z]{12}d/.test(id);
}

export function isTunnelRequest(req) {
    return req.headers[HEADERCLIENTID] !== undefined;
}

export function isTunnelClient(req) {
    return req.headers[WSHEADERCLIENTID] !== undefined;
}

export function getRequestTunnelClientId(req) {
    if (isTunnelRequest(req)) {
        return req.headers[HEADERCLIENTID];
    }
    return null;
}

export function getTunnelClientId(req) {
    if (isTunnelClient(req)) {
        return req.headers[WSHEADERCLIENTID];
    }
    return null;
}